import 'package:flutter/material.dart';
import 'package:flutter_card_swiper/flutter_card_swiper.dart';
import 'package:get/get.dart';
import 'package:personinfo/model/home/UserModel.dart';
import 'package:personinfo/states/appController.dart';
import 'package:personinfo/widgets/common/LineNav.dart';
import 'package:personinfo/widgets/common/MiniTitleNav.dart';

import '../widgets/common/CommonWidget.dart';
import '../widgets/common/IconText.dart';

class Person extends StatefulWidget {
  const Person({super.key});

  @override
  State<StatefulWidget> createState() => _PersonState();
}

class _PersonState extends State<Person> {
   late String userName;
  @override
  Widget build(BuildContext context) {
    return GetBuilder<AppController>(
        init: AppController(),
        builder: (controller){
          UserModel? userModel = controller.user;
          userName = userModel?.name ?? "";
        return Scaffold(
            backgroundColor: Theme.of(context).colorScheme.onPrimary,
            appBar: commonWidget.appBar(
                title: const Text("关于我们") ,
                actions: [
                  GestureDetector(
                    onTap: (){
                      Navigator.pushNamed(context, "/setting");
                    },
                    child: const Row(
                      children: [
                        Icon(Icons.settings),
                        Text("设置", style: TextStyle(fontWeight: FontWeight.bold,fontSize: 15),)
                      ],
                    ),
                  ),
                  SizedBox(width: 16,)
                ]
            ),
            body: SingleChildScrollView(
              child: Column(
                children: [
                  Container(
                    color: Color.fromRGBO(244, 243, 248, 1),
                    padding: const EdgeInsets.fromLTRB(16 , 10, 16, 16),
                    child: Flex(
                      direction: Axis.horizontal,
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            Image.asset("assets/images/login.jpg",width: 80,),
                            const SizedBox(width: 10,),
                            if(userName.isEmpty) Text("描述")
                            else Column(
                              crossAxisAlignment: CrossAxisAlignment.start ,
                              children: [
                                Text(userName, style: TextStyle(fontWeight: FontWeight.bold,fontSize: 16),),
                                Text("年龄：18", style: TextStyle(fontWeight: FontWeight.bold,fontSize: 12),)
                              ],
                            )
                          ],
                        ),
                        const Icon(Icons.arrow_right)
                      ],
                    ),
                  ),
                  const SizedBox(height: 2,),
                  const MiniTitleNav(title: "我的订单",showLine: false,),
                  const SizedBox(height: 20,),

                  GridView.count(
                    shrinkWrap: true,
                    crossAxisCount: 5,
                    crossAxisSpacing:5,
                    childAspectRatio: 1.5,
                    mainAxisSpacing:5,
                    padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
                    children: [
                      IconText(icon: Icons.airplay_sharp, text: "待处理",iconColors: const Color.fromRGBO(166, 1, 227, 1),iconFontSize: 26,
                        onTap: (){
                          Navigator.pushNamed(context, "/orderList",arguments: {"index": 0});
                        },
                      ),
                      IconText(icon: Icons.search_off_rounded, text: "待确认",iconColors: Color.fromRGBO(55, 192, 0, 1),iconFontSize: 26,
                        onTap: (){
                          Navigator.pushNamed(context, "/orderList",arguments: {"index": 1});
                        },),
                      IconText(icon: Icons.file_copy, text: "待支付",iconColors: Color.fromRGBO(233, 1, 1, 1),iconFontSize: 26,
                        onTap: (){
                          Navigator.pushNamed(context, "/orderList",arguments: {"index": 2});
                        },
                      ),
                      IconText(icon: Icons.file_open, text: "已完成",iconColors: Color.fromRGBO(2, 196, 100, 1),iconFontSize: 26,
                        onTap: (){
                          Navigator.pushNamed(context, "/orderList",arguments: {"index": 3});
                        },
                      ),
                      IconText(icon: Icons.event_busy, text: "已取消",iconColors: Color.fromRGBO(0, 177, 254, 1),iconFontSize: 26,
                        onTap: (){
                          Navigator.pushNamed(context, "/orderList",arguments: {"index": 4});
                        },
                      ),
                    ],
                  ),
                  SizedBox(height: 18,),
                  LineNav().heightLine(),
                  SizedBox(height: 10,),
                  const MiniTitleNav(title: "我的寻车",showLine: false,),
                  SizedBox(height: 20,),
                  GridView.count(
                    shrinkWrap: true,
                    crossAxisSpacing:5,
                    crossAxisCount: 5,
                    mainAxisSpacing:5,
                    childAspectRatio: 1.5,
                    padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
                    children:  [
                      IconText(icon: Icons.airplay_sharp, text: "发布寻车",iconColors: Color.fromRGBO(166, 1, 227, 1),iconFontSize: 26,
                        onTap: (){
                          Navigator.pushNamed(context, "/publishSearchCar");
                        }
                      ),
                      IconText(icon: Icons.search_off_rounded, text: "未处理",iconColors: Color.fromRGBO(55, 192, 0, 1),iconFontSize: 26,
                        onTap: (){
                          Navigator.pushNamed(context, "/mySearchCar",arguments: {"index": 0, "subIndex": 1});
                        },
                      ),
                      IconText(icon: Icons.file_copy, text: "已完成",iconColors: Color.fromRGBO(233, 1, 1, 1),iconFontSize: 26,
                        onTap: (){
                          Navigator.pushNamed(context, "/mySearchCar",arguments: {"index": 0, "subIndex": 3});
                        },
                      ),
                      IconText(icon: Icons.file_open, text: "已过期",iconColors: Color.fromRGBO(2, 196, 100, 1),iconFontSize: 26,
                        onTap: (){
                          Navigator.pushNamed(context, "/mySearchCar",arguments: {"index": 1, "subIndex": 0});
                        },
                      ),
                      IconText(icon: Icons.event_busy, text: "已取消",iconColors: Color.fromRGBO(0, 177, 254, 1),iconFontSize: 26,
                        onTap: (){
                          Navigator.pushNamed(context, "/mySearchCar",arguments: {"index": 2, "subIndex": 0});
                        },
                      ),
                    ],
                  ),
                  SizedBox(height: 18,),
                  LineNav().heightLine(),
                  commonWidget.titleBox(title: '我的专属客服务',showMore: true),
                  LineNav().heightLine(),
                  commonWidget.titleBox(title: '我的消息',badge: '10', onTap: (){
                    Navigator.pushNamed(context, "/messageNotify",arguments: {"index": 0});
                  }),
                  LineNav().heightLine(),
                  const MiniTitleNav(title: "历史记录",showLine: false,),
                  const SizedBox(height: 20,),
                  GridView.count(
                    shrinkWrap: true,
                    crossAxisCount: 5,
                    childAspectRatio: 1.5,
                    mainAxisSpacing: 5,
                    padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
                    children:   [
                      IconText(icon: Icons.airplay_sharp, text: "数据统计",iconColors: Color.fromRGBO(166, 1, 227, 1),iconFontSize: 26,onTap: (){
                        Navigator.pushNamed(context, "/dataStatic");
                      },),
                      IconText(icon: Icons.search_off_rounded, text: "订单记录",iconColors: Color.fromRGBO(55, 192, 0, 1),iconFontSize: 26,),
                      IconText(icon: Icons.file_copy, text: "寻车记录",iconColors: Color.fromRGBO(233, 1, 1, 1),iconFontSize: 26),
                      IconText(icon: Icons.file_open, text: "车源浏览",iconColors: Color.fromRGBO(2, 196, 100, 1),iconFontSize: 26),
                    ],
                  ),
                  SizedBox(height: 18,),
                  LineNav().heightLine(),
                  SizedBox(height: 40,)
                ],
              ),
            )
        );
    });
  }
}
